package com.five.controller.backstage;

import com.alibaba.fastjson.JSON;
import com.five.dao.backstage.FacilityDao;
import com.five.dao.backstage.RoomFacDao;
import com.five.dao.impl.backstage.FacilityDaoImpl;
import com.five.entity.backstage.Facility;
import com.five.entity.backstage.TRoomFacility;
import com.five.util.LayTable;
import com.five.util.Page;
import com.five.util.TransBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 常鹏宇
 * @Description:
 * @Date: 2020/11/12 11:42
 */

@RestController
@RequestMapping("facility")
public class FacilityController {
    @Autowired
    private FacilityDao facilityDao;
    @RequestMapping("selectFacility")
    @ResponseBody
    public LayTable selectFacility(Page pageInfo,Facility facility){
        List<Map> maps = facilityDao.selectFacility(pageInfo, facility);
        int count = facilityDao.count(facility);
        List populate = TransBean.populate(Facility.class, maps);
        LayTable layTable = new LayTable(count, populate);
        return layTable;
    }
    @RequestMapping("selectTypeid")
    @ResponseBody
    public List<Map> selectTypeid(){
        return facilityDao.selectTypeid();
    }

    @RequestMapping("addAndUpdFAC")
    @ResponseBody
    public void addAndUpdFAC(Facility facility){
        facilityDao.addAndUpdFAC(facility);
    }

    @RequestMapping("DelFacility")
    @ResponseBody
    public void delFacility(Facility facility){ facilityDao.delFacility(facility); }

    @RequestMapping("bad")
    public int updata(Integer id){
        int i=facilityDao.bad(id);
        if (i>0){
            return i;
        }
        return -1;
    }
    @RequestMapping("good")
    public int updatagood(Integer id){
        int i=facilityDao.good(id);
        if (i>0){
            return i;
        }
        return -1;
    }
}
